/**
 * <p>Title: SmartPaymentsClient_JavaHTTPPost</p>
 *
 * <p>Description: A simple example to show how to use HTTP POST to send
 * transactions to the SmartPayments Web Service</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: TPI Software</p>
 *
 * @author Andy Chau
 * @version 1.0
 */

public class SmartPaymentsClient {
    public static void main(String[] args) {
        com.tpi.smartpayments.SmartPayments sp = new com.tpi.smartpayments.SmartPayments("https://www.tpisoft.com/SmartPayments/Transact.asmx");
        sp.setVerbose(true);
        System.out.println(sp.getUrl());
        com.tpi.smartpayments.Response resp = null;
        try
        {
            System.out.println("-----------------------------------------------------------");
            System.out.println("process a credit card Sale transaction");
            System.out.println("-----------------------------------------------------------");
            resp = sp.processCreditCard("test", "123", "Sale", "4444333322221111", "1213", "4444333322221111=121399999999", "John Doe", "1.00", "INV123", "", "98052", "123 Main Street", "123", "");
            System.out.println(resp.toString());

            if (resp.getResult() == 0)
                System.out.println("-------- APPROVED --------");
            else
                System.out.println("-------- DECLINED " + resp.getResult() + " --------");

            System.out.println("-----------------------------------------------------------");
            System.out.println("attach a receipt with signature");
            System.out.println("-----------------------------------------------------------");
            resp = sp.processSignature("test", "123", "Signature4", "1,1^5,5^~", resp.getPNRef(), "", "", "");
            System.out.println(resp.toString());

            System.out.println("-----------------------------------------------------------");
            System.out.println("process a credit card Auth transaction");
            System.out.println("-----------------------------------------------------------");
            resp = sp.processCreditCard("test", "123", "Auth", "4444333322221111", "1213", "4444333322221111=121399999999", "John Doe", "1.00", "INV123", "", "98052", "123 Main Street", "123", "");
            System.out.println(resp.toString());

            if (resp.getResult() == 0)
                System.out.println("-------- APPROVED --------");
            else
                System.out.println("-------- DECLINED " + resp.getResult() + " --------");

            System.out.println("-----------------------------------------------------------");
            System.out.println("process a credit card PostAuth transaction");
            System.out.println("-----------------------------------------------------------");
            String origAuthReferenceNum = resp.getPNRef();
            resp = sp.processCreditCard("test", "123", "Force", "", "", "", "", "1.00", "", origAuthReferenceNum, "", "", "", "");
            System.out.println(resp.toString());

            if (resp.getResult() == 0)
                System.out.println("-------- APPROVED --------");
            else
                System.out.println("-------- DECLINED " + resp.getResult() + " --------");

            System.out.println("-----------------------------------------------------------");
            System.out.println("process a credit card void transaction");
            System.out.println("-----------------------------------------------------------");
            origAuthReferenceNum = resp.getPNRef();
            resp = sp.processCreditCard("test", "123", "Void", "", "", "", "", "", "", origAuthReferenceNum, "", "", "", "");
            System.out.println(resp.toString());

            if (resp.getResult() == 0)
                System.out.println("-------- APPROVED --------");
            else
                System.out.println("-------- DECLINED " + resp.getResult() + " --------");

            System.out.println("-----------------------------------------------------------");
            System.out.println("process a check sale transaction");
            System.out.println("-----------------------------------------------------------");
            resp = sp.processCheck("test", "123", "Sale", "1", "123123123", "1234567890", "1.00", "", "John doe", "WA12345", "123-12-1234", "1/1/1970", "WA", "Personal", "");
            System.out.println(resp.toString());

            if (resp.getResult() == 0)
                System.out.println("-------- APPROVED --------");
            else
                System.out.println("-------- DECLINED " + resp.getResult() + " --------");

            String date = java.text.SimpleDateFormat.getDateInstance(java.text.DateFormat.SHORT).format((new java.util.Date()));
            System.out.println("-----------------------------------------------------------");
            System.out.println("Get a detail card report " + date);
            System.out.println("-----------------------------------------------------------");
            com.tpi.smartpayments.TrxDetail reportWs = new com.tpi.smartpayments.TrxDetail("https://www.tpisoft.com/Admin/ws/TrxDetail.asmx");
            String reportResp = reportWs.GetCardTrx("test", "123", "1", "", date, date, "", "", "", "", "", "", "", "", "" , "", "", "false", "", "", "", "", "", "", "", "", "", "", "");
            System.out.println(reportResp);

            System.out.println("-----------------------------------------------------------");
            System.out.println("Get a summary card report for " + date);
            System.out.println("-----------------------------------------------------------");
            reportResp = reportWs.GetCardTrxSummary("test", "123", "1", date, date, "", "", "", "", "", "false", "", "", "" , "", "", "", "", "", "", "");
            System.out.println(reportResp);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
